import java.util.Stack;

import static java.lang.System.exit;

public class MyQueue <E> {

    //链表实现
    //记录头结点
    //记录末尾结点
    static class Node<E> {
        Node next;
        E val;

        public Node(E val) {
            this.val = val;
        }
    }

    public Node head;
    public Node tail;

    //尾插
    public void add(E data) {
        Node cur = new Node<>(data);
        if(head==null) {
            head=cur;
            tail=cur;
            return;
        }
        tail.next = cur;
        tail = tail.next;
    }

    //头删
    public void Pop() {
        //链表为空退出
        if (empty()) {
            System.out.println("队列为空");
            tail=null;
            exit(0);
        }
        head = head.next;
    }

    public void display() {
        while (!empty()) {
            System.out.print(top()+" ");
        }
        System.out.println();
    }

    public boolean empty() {
          return head==null;
    }
    /** 返回队头元素 */
    public E top() {
        if (empty()) {
            System.out.println("队列为空");
            tail=null;
            exit(0);
        }
        Node cur=head;
        head=cur.next;
        return (E) cur.val;
    }

    public static void main(String[] args) {

        System.out.println(-2>-3);

    }
    public boolean isValid(String s) {
        Stack<Character> stack=new Stack<>();
        for (int i = 0; i < s.length(); i++) {
            //当为左括号时退出
            if('[' == s.charAt(i) ||'{' == s.charAt(i)||'(' == s.charAt(i)) {
                stack.add(s.charAt(i));
            }
            else{
            //当为空时
            if(stack.empty()) {
                return false;
            }
            if((']' == s.charAt(i)&&stack.peek()!='[') ||
                    ('}' == s.charAt(i)&&stack.peek()!='{')||
                    (')' == s.charAt(i)&&stack.peek()!='(')) {
                return false;
            }
            stack.pop();
            }
        }
        //当为空时
        if(!stack.empty()) {
            return false;
        }
        return true;
    }
    Stack<Integer> stack=new Stack<>();
    public int evalRPN(String[] tokens) {

        for (int i = 0; i < tokens.length; i++) {
            if (!tokens[i].equals("+")&&!tokens[i].equals("-")&&!tokens[i].equals("*")&&!tokens[i].equals("/")) {
               stack.add(Integer.parseInt(tokens[i]));
            } else {
                int a1=stack.pop();
                int a2=stack.pop();
                switch(tokens[i].charAt(0)) {
                    case '+':
                       stack.add(a1+a2);
                        break;
                    case '-':
                        stack.add(a2-a1);
                        break;
                    case '*':
                        stack.add(a2*a1);
                        break;
                    case '/':
                        stack.add(a2/a1);
                        break;
                }
            }
        }
        return stack.pop();
    }
}
